package com.coc.controller.iofile;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelReader;
import com.alibaba.excel.read.metadata.ReadSheet;
import com.coc.core.listener.DemoDataListener;
import com.coc.entity.core.JsonResult;
import com.coc.entity.core.ResultTool;
import com.coc.entity.iofile.DemoData;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("easyExcel")
public class EasyExcelController {
    /**
     *
     * @param file
     * @return easyExcel示例
     * @throws IOException
     */
    @RequestMapping("/demoUpload")
    public JsonResult demoUpload(@RequestParam("file") MultipartFile file)throws IOException {
        ExcelReader excelReader =EasyExcel.read(file.getInputStream(), DemoData.class,new DemoDataListener()).build();
        ReadSheet readSheet = EasyExcel.readSheet(0).build();
        excelReader.read(readSheet);
        excelReader.finish();
        return ResultTool.success();
    }

}
